class Week {
  constructor(obj) {
    this.init(obj)
  }

  init(obj) {
    const that = this
    obj.each(function(i) {
      $(this).click(function() {
        that.weekClick(i, obj)
      })
    })
    const w = new Date().getDay()
    const d = w === 0 ? 6 : w - 1
    this.weekClick(d, obj)
  }

  weekClick(num, obj) {
    obj
      .removeClass('on')
      .eq(num)
      .addClass('on')
    if (obj.length) {
      const con = obj
        .parent()
        .siblings('div')
        .find('>div')
      const weekDl = con.find('dl').eq(num)
      const posi = weekDl.position()
      con.animate({ scrollTop: posi.top }, 200)
    }
  }
}

export default Week
